
//
//  Ext+UIButton.swift
//  VBo
//
//  Created by 赵世得 on 2016/10/22.
//  Copyright © 2016年 Zh. All rights reserved.
//

import UIKit
extension UIButton{
    
    convenience init(setImage: String, backImg:String, target: Any?, action: Selector) {
        self.init()
        self.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        self.setImage(UIImage(named: setImage), for: UIControlState.normal)
        self.setImage(UIImage(named: "\(setImage)_highlighted"), for: UIControlState.highlighted)
        self.setBackgroundImage(UIImage(named: backImg), for: UIControlState.normal)
        self.setBackgroundImage(UIImage(named: "\(backImg)_highlighted"), for: UIControlState.highlighted)
        self.sizeToFit()
    }
    
    
    convenience init(setImg: String? = nil , title:String? = nil , target: Any?, action: Selector) {
        self.init()
        self.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        if let img = setImg {
            self.setImage(UIImage(named: img), for: UIControlState.normal)
            self.setImage(UIImage(named: "\(img)_highlighted"), for: UIControlState.highlighted)
        }
        if let tit = title {
            setTitle(tit, for: UIControlState.normal)
            setTitleColor(UIColor.darkGray, for: UIControlState.normal)
            setTitleColor(UIColor.orange, for: UIControlState.highlighted)
            titleLabel?.font = UIFont.systemFont(ofSize: 14)
        }
       
        self.sizeToFit()
    }
    
    convenience init(setImg: String , title:String  ,font: CGFloat, textColor: UIColor, target: Any?, action: Selector) {
        self.init()
        self.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        self.setBackgroundImage(UIImage(named: setImg), for: UIControlState.normal)
        self.setTitle(title, for: UIControlState.normal)
        self.setTitleColor(textColor, for: UIControlState.normal)
        titleLabel?.font = UIFont.systemFont(ofSize: font)
        
        self.sizeToFit()
    }
    
}
